//
//  ViewController.m
//  TLLabelDemo
//
//  Created by Tianlong on 2017/6/28.
//  Copyright © 2017年 Tianlong. All rights reserved.
//

#import "ViewController.h"
#import "TLLabel.h"

@interface ViewController ()<TLLabelDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    /** 
     温馨提示：保持普通和高亮文字字体一致，单行文字长度超出label长度显示点点点时右边不会有间距
     */
    TLLabel *label = [[TLLabel alloc] init];
    label.text = @"ad321@12340#89hellohe#56llohellohellohellohellohellollohellollohello";
    label.numberOfLines = 1;
    label.textColor = [UIColor whiteColor];
    label.backgroundColor = [UIColor redColor];
    //label.lineBreakMode = NSLineBreakByTruncatingTail;
    label.font = [UIFont systemFontOfSize:20];
    label.frame = CGRectMake(10, 100, self.view.bounds.size.width-20, 100);
    
    NSArray *keyArray = @[@"321",@"#89",@"#56"];
    //keyArray= @[];
    //配置高亮设置
    NSDictionary *dict = @{
                           NSForegroundColorAttributeName : [UIColor blueColor],
                           //NSFontAttributeName : [UIFont systemFontOfSize:20],
                           NSFontAttributeName : [UIFont fontWithName:@"Helvetica" size:16],
                           NSKernAttributeName:@(0)//字间距,会影响1行尾部是点点点那种，点点点不贴着控件的最右边
                           };
    //设置高亮属性
    label.attributeDict = dict;
    //设置要被高亮的文字
    label.attributeTextArray = keyArray;
    
    
    //代理 block 任君采撷
    label.delegate = self;
    
    //点击了高亮文字
    [label setTouchedHighLightText:^(TLLabel *label, NSString *string, NSRange range) {
        
    }];
    //点击了高亮文字以外的部分
    [label setTouchedOtherText:^{
    }];
    [self.view addSubview:label];
    
    
}

-(void)tlLabel:(TLLabel *)label touchedText:(NSString *)touchedText touchedRange:(NSRange)range{
    NSLog(@"%s %@",__FUNCTION__,touchedText);
}

-(void)touchedOtherText:(TLLabel *)label{
    NSLog(@"%s",__FUNCTION__);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
